From 358d9ef5a377410970230ed0df77a8a7740503aa Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 26 Oct 2004 05:44:54 +0000 Subject: [PATCH] Bug 774: section=new does not jump to the added section after save --- includes/EditPage.php | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 552aaa5ca8..1bacbef5c9 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -222,7 +222,11 @@ class EditPage { if ( ! $isConflict ) { # All's well $sectionanchor = ''; - if( $this->section != '' ) { + if( $this->section == 'new' ) { + if( $this->summary != '' ) { + $sectionanchor = $this->sectionAnchor( $this->summary ); + } + } elseif( $this->section != '' ) { # Try to get a section anchor from the section source, redirect to edited section if header found # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded # for duplicate heading checking and maybe parsing @@ -231,17 +235,7 @@ class EditPage { # headline would need to be parsed to improve this #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) { if($hasmatch and strlen($matches[2]) > 0) { - global $wgInputEncoding; - $headline = do_html_entity_decode( $matches[2], ENT_COMPAT, $wgInputEncoding ); - # strip out HTML - $headline = preg_replace( "/<.*?" . ">/","",$headline ); - $headline = trim( $headline ); - $sectionanchor = '#'.urlencode( str_replace(' ', '_', $headline ) ); - $replacearray = array( - '%3A' => ':', - '%' => '.' - ); - $sectionanchor = str_replace(array_keys($replacearray),array_values($replacearray),$sectionanchor); + $sectionanchor = $this->sectionAnchor( $matches[2] ); } } @@ -652,6 +646,28 @@ htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) . return true; } + /** + * Format an anchor fragment as it would appear for a given section name + * @param string $text + * @return string + * @access private + */ + function sectionAnchor( $text ) { + global $wgInputEncoding; + $headline = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding ); + # strip out HTML + $headline = preg_replace( '/<.*?' . '>/', '', $headline ); + $headline = trim( $headline ); + $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) ); + $replacearray = array( + '%3A' => ':', + '%' => '.' + ); + return str_replace( + array_keys( $replacearray ), + array_values( $replacearray ), + $sectionanchor ); + } } ?> -- 2.20.1